package com.southpark.demo.view.components
{
	import mx.controls.ComboBox;
	import mx.events.FlexEvent;
	
	public class DynamicComboBox extends ComboBox
	{
		
		private var previousSelectedIndex:int;
		
		public function DynamicComboBox()
		{
			super();
		}
		
		override public function set dataProvider(value:Object):void
		{
			if (selectedIndex != -1)
			{
				addEventListener(FlexEvent.UPDATE_COMPLETE,onUpdateComplete);
				previousSelectedIndex = selectedIndex;
			};
			
			super.dataProvider = value;
		}
		
		private function onUpdateComplete(event:FlexEvent):void
		{
			removeEventListener(FlexEvent.UPDATE_COMPLETE,onUpdateComplete);
			selectedIndex = previousSelectedIndex;
		}
	}
}